/**
 * @file bsp_uart.h
 * @brief 
 * @author  ()
 * @version 1.0
 * @date 2024-09-13
 * @ingroup bsp
 * @copyright Copyright (C) 2019 Queclink Wireless Solutions (ShenZhen) Co., Ltd. All Rights Reserved.
 * 
 * @par 修改日志:
 * <table>
 * <tr><th>Date       <th>Version <th>Author  <th>Description
 * <tr><td>2024-09-13 <td>1.0     <td>     <td>内容
 * </table>
 */
#ifndef __BSP_UART__H
#define __BSP_UART__H

#include "hal_adapter.h"
#include "FreeRTOS.h"
#include "semphr.h"
#include "public/ring_buffer.h"
#include "hal_adapter.h"

/* USER CODE BEGIN PFP */
#if defined(__ICCARM__)
/* New definition from EWARM V9, compatible with EWARM8 */
int iar_fputc(int ch);
#define PUTCHAR_PROTOTYPE int putchar(int ch)
#elif defined ( __CC_ARM ) || defined(__ARMCC_VERSION)
/* ARM Compiler 5/6*/
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#elif defined(__GNUC__)
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#endif /* __ICCARM__ */
/* USER CODE END PFP */

/* Macro define************************************** */
#define SEARCH_LIST(i, list) \
    for(i = 0; i < sizeof(list) / sizeof(list[0]); i++)  

/* Typedef struct************************************ */
typedef struct uart_periph
{
    int                 num;
    uint8_t           isr_prio[2]; 
    IRQn_Type           isr_num;  
    UART_HandleTypeDef  *uart; 
    ringBuffer_t        rx_ring_buff;
    ringBuffer_t        tx_ring_buff;
}uart_periph_t;

/* Function declaration****************************** */
int32_t bsp_uart_init(int16_t num);
ssize_t bsp_uart_itwrite(int16_t num, const void *buf, size_t count);
int32_t bsp_uart_read(int16_t num, void* buffer, size_t size);
void hdl_serial_interrupt_handler(int16_t num);
int32_t bsp_uart_set_baudrate(int16_t num, uint32_t bps);
void bsp_uart_waitfor_transmit_finished(int16_t num);
int32_t tx_buf_clr(int16_t num);
int32_t rx_buf_clr(int16_t num);
int32_t tx_buf_flush(int16_t num);
#endif